﻿using CMS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class MemberProvider : IProvider<Menber>
    {
        private CargorDBModel1 db=new CargorDBModel1();
        public int Delete(Menber t)
        {
            if (t == null) return 0;
            var model=db.Menber.ToList().FirstOrDefault(item=>item.Id==t.Id);
            if (model != null)
            {
                db.Menber.Remove(model);
                return db.SaveChanges();
            }
            return 0;
        }

        public int Insert(Menber t)
        {
           if(t == null) return 0;
           //我们在AddMenber里面添加已经做了判断所以在这直接添加
           db.Menber.Add(t);
            return db.SaveChanges();
        }

        public List<Menber> Select()
        {
            return db.Menber.ToList();
        }

        public int Update(Menber t)
        {
         if(t==null) return 0;
         var model=db.Menber.ToList().FirstOrDefault(item=> item.Id==t.Id);
            if (model != null)
            {
                model.Password=t.Password;
                model.Role=t.Role;
                int count=db.SaveChanges();
                return count;
            }
            return 0;
        }
    }
}
